Search for notes by fellow students, in your own course and all over the country.
Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.
Document Preview
Extracts from the notes are below, to see the PDF you'll receive please use the links above
Overview of Computer Networks
Norman Matloff
Dept
...
Matloff
April 11, 2005
Contents
1
Significance of Networks
3
1
...
3
1
...
3
1
...
3
2
An Introductory Example
3
3
The Famous, Overrated But Useful 7-Layer Model
5
3
...
5
3
...
1
Physical Layer
...
1
...
6
3
...
3
Network Layer
...
1
...
6
3
...
5
Session Layer
...
1
...
7
3
...
7
Application Layer
...
7
3
...
1
8
TCP/IP Overview
...
1
...
1
...
Datagram Communication
...
1
...
11
4
...
5
Peer Communication
...
1
...
11
4
...
7
5
9
4
...
2
4
...
What Makes a Connection Unique
...
Sample TCP/IP Application: NFS
...
1
13
TCP Socket Example
...
1
...
1
...
2
Source Code
...
19
UDP Socket Examples
...
2
...
20
5
...
2
Advanced Use of Sockets
...
3
5
...
23
Debugging Client/Server Programs
...
1
TCP
...
2
IP
...
3
Ethernet
...
1
History
The key to the computer revolution of the 1980s was the invention of the microprocessor in the 1970s
...
The computer revolution of the late 1990s, now continuing int the 21st century, involves computer networks,
whose existence is enriching our society in countless different ways
...
2
What Are Networks Used For?
A simplified but worthwhile description of the uses of computer networks might be as follows:
• Sharing of hardware: For example, several PCs might be networked together in a wired or wireless
local area network (LAN) to share a printer
...
Here the sharing involves both LANs and wide area networks (WANs), especially the latter
...
3
Which Aspects of Networks Are Important to Know?
Networks touch upon virtually every aspect of computing today
...
e
...
It should be noted carefully that it is important to know both the software and non-software aspects of
networks—the latter meaning the hardware, the protocols,1 the quantitative performance issues and so on
...
Moreover, many jobs you
might interview for might be as system administrators; in such positions, knowing the physical structure of
networks is just as important as knowing how the network software works
...
3
Here we have three individual LANs, labeled A, B and C, tied together in an internet
...
) The address names of the nodes here, such as saturn
...
com, use the IP format which will be
discussed later
...
The Internet is a special internet connecting TCP/IP networks worldwide
...
Recall that in any computer, each I/O device’s interface has a specific port number or address
...
Whenever a program, usually the operating system
(OS), reads from the keyboard, the value 50 would go onto the computer’s address bus
...
Whenever the OS reads from or writes to the LAN, it does so via the NIC, using the
NIC’s assigned address
...
• The NIC also has a LAN address, typically a 48-bit Ethernet ID number hardwired into the NIC at the
time of manufacture and unique among all NICs in the world of that LAN type
...
3
• At the TCP layer of the network software, we also speak of ports which are purely software IDs that
have nothing to do with port numbers like 60 above
...
2
Another similar term is intranet, which refers to a private collection of networks, say within a particular company, which we
do not wish to make accessible worldwide
...
4
Suppose I buy an Ethernet card and install it in saturn, but later swap it with the one in citroen
...
A computer can be connected to more than one network, as is the case with mars
...
com here
...
In addition, a computer can even
have more than one name associated with the same NIC
...
xyz
...
com associated with the interface to network A, and its names abc
...
abc
...
Basically, TCP/IP is ubiquitous today for general-purpose usage
...
Since the protocol ID (e
...
0x0800 for TCP/IP, 0x8137 for Netware, etc
...
This is especially useful if the same computer is running two or more
protocols
...
The jagged line between citroen
...
com and angus
...
edu is a phone line, dedicated to communication
between the two machines, operating 24 hours a day
...
• We can put in a phone line (or microwave link, etc
...
3
The Famous, Overrated But Useful 7-Layer Model
Every network textbook includes a picture of the famous “seven-layer” model
...
Nevertheless, it serves as a useful
overview of the field
...
3
...
3
...
1
Physical Layer
This is concerned with the nature of the physical media (metal or optical cable, free-space microwave, etc
...
5
There is also the question of signal form; the signals themselves may be in the form of pure 0-1 bits, or may
be in the form of certain frequencies
...
A major issue is the form of the medium, both in terms of the materials it uses and its topology
...
More complicated networks, including Ethernets, may consist of more than one cable, with all of
them connected via a hub
...
3
...
2
Data Link Layer
For example, in an Ethernet, this layer is concerned with ensuring that two network stations connected to
the same cable do not try to access the line at the same time
...
5
Here is an overview of how the Ethernet MAC protocol works, using a “listen before talk” approach
...
If so, it generates a random backoff time, waiting this amount of time before trying again
...
There is a small chance that another node actually had been sending but due to signal propagation delay the
transmission had not yet reached the first node
...
Both nodes will sense the collision, and again wait random amounts of time before trying again
...
e
...
6
Messages may be broken up into pieces before being sent
...
3
...
3 Network Layer
This is the routing layer
...
1
...
This transfer will
take a long time (by network standards), and we certainly don’t want it to monopolize the network during
4
In a small Ethernet, we would not even have two nodes on one cable; we would just have each station connected to a different
port in the hub
...
6
This phrasing implies that the frame will be sent only to another machine on the same Ethernet
...
See the description of the Network layer below
...
We also must deal with the fact that the buffer space at holstein won’t be large enough to deal
with a 100-megabyte message
...
But we don’t want to burden the user at saturn with the task of
breaking up the 100 megabytes into pieces, nor do we want to burden the user at holstein with the reassembly
of the messages
...
3
...
5
Session Layer
This layer is concerned with management of a session, i
...
the duration of a connection between two network
nodes
...
Actually, TCP does this in some senses, as does the socket interface to TCP, which is very much like
the interfaces for reading or writing a file (described in more detail later)
...
1
...
In the old days, this could mean ASCII at one end and EBCDIC on the other end
...
3
...
7
Application Layer
You can write programs at the application layer yourself, and of course you use many programs written by
others, such as ftp, Web browsers, e-mail utilities, and so on
...
2
How the Layers Interact
The Physical Layer is obviously implemented in hardware
...
8 These days the Network Layer is also usually hardware; as noted
above, Ethernet hubs are now common in the home, and include routing capabilities
...
Information is communicated from one layer to the next
...
The file-transfer program, say ftp, works in the Application Layer
...
These functions will in turn call functions
7
The “users” here are the application programs being run, e
...
ftp at saturn and ftpd (the FTP server) at holstein
...
9
In some cases a layer is “skipped
...
8
7
for TCP operations in the Transport Layer, which will themselves call functions for IP operations at the
Network layer
...
g
...
At any given layer, a function passes the message in a packet of bits to the
next lower layer
...
Say we are using the put command in ftp to copy a file named zyx to the destination machine
...
At this point the packet consists only of the data, the socket number and
the number of bytes of data, and will be handed over to TCP
...
IP will add to the packet a code indicating the fact that this is a TCP packet (as opposed to UDP, another type
of communication service offered in the TCP/IP protocol), plus the source and destination IP addresses, and
so on, and pass the packet to the NIC
...
The packets sent at the physical level have a special name, frames
...
The packet will
now travel up the protocol stack, and will shrink as it does so
...
Note also that as the packet gets routed through intermediate machines on its way to the destination, at each
of these intermediate machines it will travel up the protocol stack to the Network Layer (i
...
IP), which will
check to see whether it has reached the destination, and then upon finding that it hasn’t, it will be sent back
down the stack for transmission to the next machine in its path to the destination
...
We will give only a short introduction
...
1
TCP/IP Overview
A famous and very common network protocol is TCP/IP
...
For the
latter reason, it is now part of other OSs, such as Windows
...
This is a
nice feature in UNIX, as it gives us a uniform interface to both files and sockets
...
8
TCP/IP actually includes two protocols at the transport level, TCP and UDP, and one at the network level,
IP
...
1
...
As mentioned earlier, the term connection does not refer to a
physical connection, but rather to a temporary agreement set up between the source and destination nodes
concerning the processing of a sequence of ordered packets, such as the sizes of the pieces of a file sent
during a file transfer
...
If the source does not receive an acknowledgement for a given packet
within a preset amount of time, it will time out and resend the packet
...
For this reason, TCP is called a reliable protocol (though this term
should not be taken to mean “100% reliable”)
...
1
...
UDP is pretty reliable if confined to a LAN, but
problems may occur elsewhere, because for example a buffer at a router might be full and the datagram
(the term used instead of packet in the UDP case) is dropped
...
UDP is useful in applications in which we can afford to lose some messages, such as a time server, which
broadcasts time of day to client machines; if a client misses one message this is no problem, as it will pick
up the next one
...
Similarly, suppose we are broadcasting a graphics animation or a movie over a network
...
Moreover, in real-time applications like this, we can hardly afford the delay
caused by retransmitting when messages are lost or corrupted, which is what TCP would do
...
e
...
If we do wish to send the same message to everyone, the ability to do so using just
one copy can really help reduce traffic on the network
...
1
...
Datagram Communication
It is extremely important to keep in mind that TCP views all the bytes it sends during one socket
connection to consist of one long stream of bytes, with no subdivisions of any kind
...
You will see the details of writing to a socket later, but for now suffice it to say
that these two calls write 20 bytes from an array BufA1 and 30 bytes from an array BufA2 to the socket,
and those bytes will be sent to machine B
...
There will be no “fence”, no “dotted line,” etc
...
Moreover, on the receiver end at machine B, with a read() inside a while loop, we may, for instance,
receive first 15 bytes, then 25, then 10
...
) In that second chunk of 25 bytes, the first 5
of them would in this example be from the first call to write() on the sender end, with the other 5 from the
second call, but again there will be no demarcation between these two sets of 5
...
(Just as exiting a
program automatically closes all files, it also closes all sockets
...
Ptr = Buf;
do {
NBytesRead = read(SD,Ptr,BUFSIZE);
TotMsgSize += NBytesRead;
Ptr += NBytesRead;
} while (NBytesRead > 0);
So, even a single call to write() at the sender will need a loop containing read() on the receiver end, rather
than just a single call to read()
...
As opposed to TCP, in which the totality of bytes sent by the sender is just considered to be
one long stream, the bytes sent by separate calls to write() are considered to be separate from each other
...
12
So, the application programmer must make a decision
...
Things would thus be easier under UDP,
11
On the sending end, it is conceivable that even a call to write() may not send as many bytes as requested, if the OS kernel’s
write buffer is nearly full
...
Prentice-Hall, vol
...
, p
...
”
12
Not to be confused with the same term for a packet at the IP level
...
But on the other hand, with UDP the
programmer would have to add his/her own code for “chunking,” error checking, etc
...
Note that TCP has a slow startup time, due to the handshaking between the two nodes as the connection
is established
...
4
...
4
IP Addresses
Each node on the Internet has an IP address, a 32-bit number
...
The IP address of the
machine garnacha
...
ucdavis
...
237
...
236
...
For instance, if the machine has two NICs, IP must decide which
one to pass the packet to
...
1
...
Typically one of these programs will be a service provider and thus is termed the server,
and the other will be the service requester, called the client
...
15
For the application programmer, it would be extremely inconvenient to have to code the actual packet formation
...
One popular type of such functions is sockets, which to the programmer look very similar to file handles
...
Consider ftp again, for instance, with a put
operation
...
16 The two sockets were associated with each other at the time they were created
...
4
...
6
Viewing Current Socket Status
On UNIX machines, the netstat command will show you the current status of all open sockets; there is a
version on Microsoft Windows machines too
...
This node no longer exists
...
Of course, the principles are still valid, regardless of which machines we use
...
You will may see one or more ftpd processes there
...
There is another daemon, inetd, which intercepts calls to services like ftpd, invoking
these services as needed
...
14
11
operation; you should see the new socket listed
...
1
...
They may even all be accepting messages from the same remote machine
...
The ftpd service is on port 21, for instance
...
)
• server IP address
• server socket port number
• client IP address
• client (ephemeral) socket port number
The server, for example, may be involved in several TCP transactions sent from the same machine, and thus
the server needs to have some way of distinguishing between them
...
Say for example, there are two users currently on machine X, one using ftp to port 21 at machine Y, and
another using telnet to port 23 at machine Z
...
The ftp program will inform the FTP server at machine Y about this 2592 number
when it first connects to Y, and when the server sends back to X it will use this number
...
Similar statements hold for
telnet, etc
...
4
...
NFS uses the
UDP transport protocol
...
NFS actually uses Remote Procedure Call (RPC), which in turn uses UDP
...
We have earlier referred to UDP’s “unreliable”
nature, which means RPC must take its own reliability measures
...
This directory contains a number of
utilities, such as the GNU C compiler, gcc, in the file /usr/pkg/gnu/bin/gcc
...
c
as if gcc were on taco’s local disk
...
local
and so on
...
engr
...
edu:/usr/pkg /usr/pkg
On the other end, one of rosarita’s bootup files will include an export command, saying that it is all right
to allow its directory /usr/pkg to be mounted by other machines
...
Here is why the RPC mechanism is convenient
...
19 So, in the example above, when a file within /usr/pkg is referenced at
taco (our use of gcc will consist of a read to the file /usr/pkg/gnu/bin/gcc), the function open(), read(), and
so on will then do RPCs to the corresponding functions at rosarita
...
1
TCP Socket Example
Below are two C programs, a client and a server
...
The server will report to the client the load at X (defined by the output of the
UNIX commands w and ps -ax)
...
berkeley
...
engr
...
edu, respectively
...
engr
...
edu w
1:01pm up 37 days, 17:54, 2 users,
User
tty
login@ idle
JCPU
matloff ttyp1
12:58pm
1
4
matloff ttyp2
1:00pm
1
2
bslouie ttyp3
11:43am
1
42
toto%
load average: 0
...
00, 0
...
This is just a coincidence, arising from the fact that I had
telnet-ed into garnacha from toto in order to start up svr
...
13
5
...
1
Source Code
Here are the programs:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
40
41
42
43
44
45
46
47
48
49
50
51
55
56
57
58
59
60
/* WPsClient
...
User can check load on machine without logging in
(or even without being able to log in)
...
*/
/* these
#include
#include
#include
#include
#include
are needed for socket calls */
h>
h>
sin_family = AF_INET;
Addr
...
sin_addr
...
c */
/*
A server for remote versions of the w and ps
commands
...
*/
/* these
#include
#include
#include
#include
#include
are needed for socket calls */
h>
h>
h>
#define WPSPORT 2000
#define BUFSIZE 1000
int ClntDescriptor,
SrvrDescriptor;
/* server port number */
/* socket descriptor to client */
/* socket descriptor for server */
char InBuf[BUFSIZE], /* messages from client */
OutBuf[BUFSIZE]; /* messages to client */
Write()
{
int FD,NB;
FD = open("tmp
...
client");
}
Respond()
{
memset(OutBuf,0,sizeof(OutBuf)); /* clear buffer */
if (!strcmp(InBuf,"w"))
system("w > tmp
...
client");
else
system("echo ’invalid command’ > tmp
...
sin_family = AF_INET;
BindInfo
...
sin_addr
...
Also, here are some other notes on programming:
• On Solaris machines, you may need to add -lsocket and possibly -lxnet to your compile command
...
This is especially true for C++
...
• Even after a socket is closed, TCP will keep that socket alive for a while (e
...
30 seconds or so), just
in case there are still some packets to come in
...
20
Let’s see how the programs work, taking the client first
...
16
We have chosen to put our server on port 2000
...
You can see a list of well-known ports in the UNIX file
/etc/services
...
They need to be large enough for the
data we send
...
Note carefully, though, that this limit is NOT
there for the purpose of keeping our packets small; we can send as long a message as we like, with a single
call to write()
...
Lines 36-39:
We open a socket, using the socket() system call
...
The second parameter indicates the service, i
...
TCP, UDP or
others; it is TCP in this case, designated by SOCK STREAM
...
The function’s return value, assigned to SD here, is a socket descriptor, quite analogous to a file descriptor
...
Its type, sockaddr in (line 31) comes from the #include file and is a standard socket type
...
See the man pages if you are interested for more
information
...
Yet the sockaddr type is just meant as a dummy, to be replaced by another struct type
which is specific to the network protocol being used
...
” There are also types such as sockaddr ns for the Xerox
Networks Systems protocol, though of course TCP/IP has become virtually ubiquitous
...
Recall that
the user specifies an Internet host name, such as garnacha
...
edu
...
This is obtained on line 46
...
In line 47, we call memcopy(), a system call which copies strings from one part of memory to another, in
this case from various fields of the struct pointed to by HostPtr to Addr
...
(Here ‘h’ stands for “host
...
In line 51, we now connect the socket to the destination host
...
)
Note that the port number we have specified is for the port at the server, not the client
...
Line 57:
21
There are also various others, such as SOCK RAW for raw sockets
...
Note that
the function write() is identical to the one used for low-level file access, except that we have as the first
parameter a socket descriptor instead of a file descriptor
...
On line 61 we then write that message to the user’s screen
...
)
Note carefully that if we had been expecting more voluminous data from the server than is the case here, we
may have had to do repeated calls to read()
...
(And in non-UNIX environments, we must use these, since those OSs do
not treat socket and file I/O the same
...
Line 68:
Here the server creates a socket
...
This associates the socket with a particular port and with
a particular IP address on the local machine, i
...
the machine on which the program which calls bind() is
running, in this case the server machine
...
For example, suppose one of the NICs at the server machine corresponds to a local private intranet
...
Or, suppose we are running an Internet service provider (ISP)
...
acmegroceries
...
flatearthsociety
...
), each with
a different IP address
...
acmegroceries
...
In our case here, we wish this server to be accessible from via of its IP addresses, which we specify in line
79 by using the constant INADDR ANY
...
We could have had one if we wanted the client
to access this port only through a particular one of the IP addresses of the client machine
...
22
To summarize, in a server program, calling bind() associates with the given socket the port number and IP
address that “phone calls” to this socket will be allowed on
...
18
Normally we do not need to call bind() in a client program
...
If we do not call bind() in the client, then
calling connect() in the client will cause the OS to assign to the client a port, called an ephemeral port, as
well as an IP address (in the case that the client has more than one IP address)
...
(WPSPORT is the number of a port at the server, not at the client
...
Line 88:
Be calling the listen() function, we are notifying the OS that this program will be a server, not a client
...
If a call arrives when the queue is full, the call
will be discarded (so it is best when writing the client to put the call to connect() in a loop, looping until
connect() succeeds)
...
The accept() function (line 95) accepts
a pending call, returning a socket which we will use to exchange messages to the client
...
The original socket is then called a listening socket, whose job is only to listen for connection requests from
clients, rather than for actual information exchange with client
...
We read the client’s command, ”w” or ”ps”, on line 108, and then respond to the client on line 114
...
The function system() (lines 50, 52 and
54) actually submits a shell-level command
...
client
...
5
...
2
Who Shall I Say Is Calling?
There are many other TCP/IP functions available
...
To use this function, declare a
variable, say s, of type sockaddr in and initialize its sin family field to AF INET
...
Then the call to getpeername() will have as
its arguments to the socket descriptor (ClntDescriptor in our example here), &s and &i
...
sin addr
...
In the case of UDP, where one normally does not call connect(), this function is performed by the call to
sendto()
...
Define a variable, say hp, of type “struct hostent *”
...
sin addr, 4 and “AF INET”, assigning the return value to hp
...
5
...
2
...
c */
2
3
4
/* introductory UDP example (client), with client sending a one-line
message to server at port 4000 */
5
6
7
8
9
10
#include
#include
#include
#include
#include
h>
h>
sin_family = AF_INET;
your
...
cs
...
edu");
your
...
s_addr = *(u_long *) h_name->h_addr_list[0];
19
20
21
22
23
if ((sockfd = socket(AF_INET,SOCK_DGRAM,0)) < 0)
printf("socket error\n");
exit(1);
}
24
25
26
27
{
28
strcpy(buf,"OK");
29
30
if (sendto(sockfd,buf,strlen(buf),0,&your,sizeof(your)) < strlen(buf)) {
printf("send error\n");
exit(1);
}
31
32
33
34
35
1
}
/* BasicSrv
...
h>
#include
h>
20
9
10
#include
h>
11
12
main()
13
14
{
struct hostent *h_name;
int sockfd;
char buf[10];
struct sockaddr_in mine;
/* these two are needed as placeholders but are not used here: */
struct sockaddr_in rcvaddr;
int addlen;
15
16
17
18
19
20
21
mine
...
sin_port = htons(4000);
mine
...
s_addr = INADDR_ANY;
22
23
24
25
if ((sockfd = socket(AF_INET,SOCK_DGRAM,0)) < 0)
printf("socket error\n");
exit(1);
}
26
27
28
29
{
30
if (bind(sockfd,(struct sockaddr *)&mine,sizeof(mine)) < 0)
close(sockfd);
printf("bind error\n");
exit(1);
}
31
32
33
34
35
{
36
recvfrom(sockfd,buf,sizeof(buf),0,&rcvaddr,&addlen);
printf("%s\n",buf);
37
38
39
}
We have used the htons() function error, in order to guard against problems in communicating between bigand little-endian machines
...
To be safe, this should always be used
...
If the
server needs to reply (which it doesn’t in this case but does in most applications), it does a call to sendto(),
using the same socket and the client address which it discovered in its call to recvfrom()
...
2
...
Here
is an example:
One nice feature of UDP is that if it is used on a single network on which broadcast is physically possible,
UDP can arrange us to simultaneously send a packet to every node on that network
...
24
You can determine the broadcast address (given in IP address form) by running the ifconfig command on
UNIX machines, or winipcfg on Microsoft Windows platforms
...
21
Here is how we could change the client in the above example to do a broadcast (using the same server, but
now running on many nodes on the Ethernet):
1
/* BCastCln
...
c, no change */
6
7
8
9
10
11
12
#include
#include
#include
#include
#include
h>
h>
sin_family = AF_INET;
your
...
machines are on the network 128
...
*,
i
...
hex IP addresses 0x8078zzzz, so the broadcast address
replaces zzzz by ffff (after this program was written,
the addresses became 169
...
*; in general, run
/sbin/ifconfig to determine broadcast address */
your
...
s_addr = 0x8078ffff;
23
24
25
26
27
28
29
30
31
if ((sockfd = socket(AF_INET,SOCK_DGRAM,0)) < 0)
printf("socket error\n");
exit(1);
}
32
33
34
35
{
36
setsockopt(sockfd,SOL_SOCKET,SO_BROADCAST,&turn_option_on,
sizeof(turn_option_on));
37
38
39
strcpy(buf,"OK");
40
41
if (sendto(sockfd,buf,strlen(buf),0,&your,sizeof(your)) < strlen(buf)) {
printf("send error\n");
exit(1);
}
42
43
44
45
46
}
Another example of the advanced use of sockets is raw sockets
...
A program which
uses raw sockets must have root privileges
...
3
Nonblocking I/O
In many applications a server has sockets open to several clients at once
...
One way to handle this is to
make the sockets nonblocking, which means that a call to read() will not wait until data is ready
...
You code can then repeatedly poll all sockets, testing for input data at each one, and reading
that data if it is there
...
You will need the proper include-files; check the man
page for ioctl()
...
A
newer such tool is poll()
...
4
Debugging Client/Server Programs
As a quick check, you can first try to use telnet to check whether the server has called bind(), listen() and
accept() properly
...
What telnet does is open a connection to
a given host at a given port; whatever bytes the user types will be sent to that port, and whatever bytes the
port sends will appear on the user’s screen
...
If for example we have a server on pc8
...
ucdavis
...
cs
...
edu 1088
If we get a response here but not from our own client program, the latter may have an error in connect() or
whatever, such as misspecifying the server’s IP address or port
...
)
In general, debugging a server/client pair, using a debugging tool (which you should do when debugging
any program) will be a bit more difficult, because you will need to invoke the tool once for the server and
once for the client
...
Or, I might just use the debugging tool on the client while running the server without a debugging
tool, or vice versa
...
) to be useful
...
In our case here, that means calls to accept(), connect(), etc
...
6
...
Bytes 2-3: Destination Port
...
Bytes 8-11: Acknowledgement
...
Most
of the header is of fixed length, so we would not need this, except for the fact that the Options field below is
of variable length
...
Byte 13: Flags, which are various bits giving control information such as a PUSH command (which tells the
host not to continue accumulating bytes to send; “send whatever you have now, without waiting for more”)
...
”
Bytes 16-19: Check Sum (two bytes), for error checking, and a two-byte Urgent Pointer field
...
Remaining Bytes: Data, e
...
your e-mail message in the case of sendmail
...
)
6
...
Byte 1: Type of Service field, intended to give priority to some packets but not used much in practice
...
Bytes 4-7: Miscellaneous fields
...
If this equals, say, k, then this packet will be allowed k more hops through the
network
...
Byte 9: Transport-layer protocol (e
...
6 for TCP, 17 for UDP)
...
24
Bytes 12-15: Source IP address
...
Bytes 20-whatever: Options including blank padding to make an integral number of words
...
Remember, from the point of view of the IP layer, the “data” consists of a TCP or
UDP packet (or other packet from a higher layer)
...
3
Ethernet
Preamble: Start-of-frame indicator, a special 64-bit pattern
...
Source Ethernet ID: See Destination Ethernet ID above
...
Indicates the protocol being used, e
...
0x0800 for IP and 0x809b for Appletalk
...
Data: This consists of the IP packet (in the case of the IP protocol)
...
CRC: 32 bits
...
Postamble: End-of-frame indicator, a special 8-bit pattern
...
Suppose we
have the following IP and Ethernet (MAC) addresses:
machine
Earth
Mars
Venus
Saturn
Jeep
Honda
IP address
192
...
0
...
0
...
1
192
...
0
...
0
...
3
193
...
0
...
0
...
1
MAC address
0x0123456789ab
0x1123456789ab
0x2123456789ab
0x3123456789ab
0x4123456789ab
0x5123456789ab
All of the machines here have Class C IP addresses, which consist of a 24-bit network number and 8-bit
host-within-network number
...
0
...
0
...
Recall that argv[2] is either “w” or “ps”; let’s say it’s “ps”
...
Also, the call which wps made earlier to connect() had connected this
socket to port 2000 at venus, and the OS at honda had assigned wps an ephemeral port number, say 3056
...
The Session Layer will find in its records that this socket is for ephemeral port 3056 on TCP
...
(Note that this
passing is done by a simple function call, since we are at the same machine
...
0
...
2, respectively
...
, and finally put “ps” into the Remaining
Bytes (i
...
data) field
...
0
...
2
...
It will fill in 193
...
0
...
0
...
2
for the Destination IP
...
IP at honda will now decide how to route the IP packet it has created
...
The answer to that question will be no, since honda is on the network
193
...
0 and venus is on 192
...
0
...
There are two such routers, jeep and citroen
...
(This will probably have been hand-coded; more on this in our unit
on routing
...
So, IP will pass the packet, plus jeep’s Ethernet address, 0x4123456789ab,
to the Data Link Layer at honda
...
It will put 0x4123456789ab for the Destination
Ethernet ID, and 0x5123456789ab for the Source Ethernet ID
...
And
it will put in the entire IP packet it received from the Network Layer in for the current Data field
...
The Ethernet device driver on honda will then put the frame on network B
...
That NIC will say, “Oh, this frame is for me!” Note that the NIC will not notice that the ultimate destination
of the frame is venus; all the NIC cares about is the Destination Ethernet address, which it has seen is its
own
...
The Data Link Layer at jeep will strip off the Ethernet IDs and other Ethernet-related information
...
The Data Link Layer will know
this, since the Type field in the Ethernet frame stated that the protocol was IP
...
IP will now look at the Destination IP Address in the packet, 192
...
0
...
Since that does not match jeep’s
25
Note that it is the same protocol stack as that of mars
...
26
own address, 193
...
0
...
IP also notices that the Destination
IP Address is on network number 192
...
0, i
...
network A, which jeep’s machine is attached to via another
NIC
...
The
Ethernet Source ID will be jeep’s, i
...
0x4123456789ab, and the Ethernet Destination ID will be venus’,
0x2123456789ab
...
The frame will then go up the protocol stack at venus like it did at jeep, but in this case IP at venus will
discover that the Destination IP Address is that of venus
...
IP at venus will see in the Transport Layer Protocol
field that this is a TCP packet (and thus not, for example, UDP)
...
IP will pass the packet to TCP, along with information on the
Source IP address
...
The Session Layer will send the remainder to read(), and
svr will be able to read the “ps”
...
Note also that when wps first called
connect(), a similar sequence of events occurred then too, as honda’s TCP and venus’ TCP exchanged
messages in order to set up a connection
...
are so common that they have their own protocols
...
Suppose you are lm@abc
...
org, and your message is going to be a simple one-line greeting:
Hi, how have you been?
The client, which will be either the e-mail utility that you use, or an OS function called by that utility, will
first establish a TCP connection to the SMTP server at the remote machine, at port 25 of the server
...
com
MAIL FROM: lm@abc
...
org
DATA
Hi, how have you been?
...
)
26
There will be responses from the server for each one, but we will ignore them here
...
The HTTP server is at
port 80
...
cs
...
edu/˜matloff/gnuplot
...
cs
...
edu, at the standard HTTP port, 80
...
html HTTP/1
...
That is the HTTP command to get the given file on that machine
...
) The machine would respond by sending back the raw HTML file,
which happens to consist of the HTML code
The gnuplot mathematical graphing package is available on most Unix
systems
...
Here is some documentation: